package com.springcloud.alibabanacosconfig.mq.listener;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.springcloud.alibabanacosconfig.mq.dto.UserLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/10/22 16:03
 * @description
 * @Modify By：
 * @ModifyTime： 2019/10/22
 * @Modify marker：
 **/
@Component
@Slf4j
public class CommonMqListener {
    /**
     * 监听消费用户日志
     * @param message
     */
    @Autowired
    private ObjectMapper objectMapper;


    @RabbitListener(queues ="${log.user.queue.name}",containerFactory = "singleListenerContainer")
    protected void consumeUserLogQueue(@Payload byte[] message) {
        try {
            UserLog userLog = objectMapper.readValue(message, UserLog.class);
            log.info("监听消费用户日志 监听到消息： {} ", userLog.getApiName());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
